<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>监控页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/ztree/demo.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/ztree/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/ztree/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/ztree/jquery.ztree.excheck.js"></script>
	
	<style type="text/css">
		body{height:100%;width:100%;margin:0;padding:0;}
	</style>
	
	<SCRIPT type="text/javascript">
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes = eval(${jsonTree});
		
		//var code;
		
		/* function setCheck() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			py = $("#py").attr("checked")? "p":"",
			sy = $("#sy").attr("checked")? "s":"",
			pn = $("#pn").attr("checked")? "p":"",
			sn = $("#sn").attr("checked")? "s":"",
			type = { "Y":py + sy, "N":pn + sn};
			zTree.setting.check.chkboxType = type;
			showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
		}
		
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		} */
		
		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			//setCheck();
			/* $("#py").bind("change", setCheck);
			$("#sy").bind("change", setCheck);
			$("#pn").bind("change", setCheck);
			$("#sn").bind("change", setCheck); */
		});
		
		function configLights() {
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");  
				var nodes=zTree.getCheckedNodes(true);  
				var result='';  
				if(nodes.length==0){  
					alert("请选择路灯！");  
					return false;  
				}  
				for (var i = 0; i < nodes.length; i++) {  
					var halfCheck = nodes[i].getCheckStatus();  
					if (!halfCheck.half && !nodes[i].isParent){  
						result += nodes[i].id +',';  
					}  
				}  
				result=result.substring(0,result.lastIndexOf(","));
				
				$.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/configLights.do",
					async: false,
					dataType : "json",
					data : {
						templateId : "${templateId}",
						lightIds : result
					},
					success : function(data) {
						alert(data.msg);
						
						if(data.success==0) {
							location.href = "${pageContext.request.contextPath}/showConfig.do";
						}
					}
				});
		}
	</SCRIPT>
	
  </head>
  
  <body>
	<div class="content_wrap">
		<input type="button" value="提   交" onclick="configLights()"/>
		<div class="zTreeDemoBackground left">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	</div>
  </body>
</html>